package com.wqz.dao;

import com.wqz.pojo.Role;
import com.wqz.utils.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;

public class RoleDaoTest {

    @Test
    public void findListById() {

        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        RoleDao roleDao = sqlSession.getMapper(RoleDao.class);
        List<String> list = new LinkedList<>();
        list.add("1");
        list.add("2");
        try {
            List<Role> roleList = roleDao.findListById(list);
            for(Role role : roleList) {
                System.out.println(role);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }
    }

    @Test
    public void findArrayById() {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        RoleDao roleDao = sqlSession.getMapper(RoleDao.class);
        String[] arr = new String[]{"2","3"};
        try {
            List<Role> roleList = roleDao.findArrayById(arr);
            for(Role role : roleList) {
                System.out.println(role);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }
    }

    @Test
    public void findMapById() {
        SqlSession sqlSession = MyBatisUtil.createSqlSession();
        RoleDao roleDao = sqlSession.getMapper(RoleDao.class);
        Map<String, Object> map = new HashMap<>();
        String[] arr = new String[]{"1","3"};
        List<String> list = new LinkedList<>();
        list.add("1");
        list.add("3");
        map.put("map01", list);
        try {
            List<Role> roleList = roleDao.findMapById(map);
            for(Role role : roleList) {
                System.out.println(role);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MyBatisUtil.closeSqlSession(sqlSession);
        }
    }
}